package JUC.创建线程;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CreateCallable {
    public static void main(String[] args) {
        MyCallable myCallable = new MyCallable();
        FutureTask futureTask = new FutureTask<>(myCallable);
        new Thread(futureTask).start();
        try {
            System.out.println("最后的返回值 " + futureTask.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
class MyCallable implements Callable{
    int sum = 0;
    @Override
    public Object call() throws Exception {
        for (int i = 0; i < 10; i++) {
            sum += i;
            System.out.println(Thread.currentThread().getName() + i);
        }
        return sum;
    }
}
